#include "CMonster.h"

std::map<int, CMonster> _CMonster;

void ReadMonsterData()
{
    /* Declare the variables to be used */ 
    const char* filename = "Tables/MONSTER_TABLE.csv";
    const char field_terminator = ',';
    const char line_terminator  = '\n';
    const char enclosure_char   = '"';

    csv_parser file_parser;

    /* Define how many records we're gonna skip. This could be used to skip the column definitions. */ 
    file_parser.set_skip_lines(1);

    /* Specify the file to parse */ 
    bool isOK = file_parser.init(filename);

    /* Here we tell the parser how to parse the file */ 
    file_parser.set_enclosed_char(enclosure_char, ENCLOSURE_OPTIONAL);

    file_parser.set_field_term_char(field_terminator);

    file_parser.set_line_term_char(line_terminator);

    unsigned int row_count = -1U;

    /* Check to see if there are more records, then grab each row one at a time */ 
    while(file_parser.has_more_rows()) 
    { 
        unsigned int i = 0; 

        /* Get the record */ 
        csv_row _Row = file_parser.get_row(); 

        CMonster _TmpMonster;

        /* Print out each column in the row */ 
        for (i = 0; i < _Row.size(); i++) 
        { 
            switch(i)
            {
            case 0:
                _TmpMonster.m_Index = atoi(_Row[i].c_str());
                break;

            case 1:
                _TmpMonster.m_Level = atoi(_Row[i].c_str());
                break;

            case 2:
                _TmpMonster.m_Name = _Row[i].c_str();
                break;

            case 3:
                _TmpMonster.m_Texture = _Row[i].c_str();
                break;

            default:
                break;
            }
        }

        _CMonster[_TmpMonster.m_Index] = _TmpMonster;

        row_count++;
    }
}

const std::map<int, CMonster>* _GetMonsterMap()
{
    return &_CMonster;
}

